package sw6.pc.logic;

import java.awt.Rectangle;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JComponent;

public class Menu {
	
	ArrayList<Menu> mMenus = new ArrayList<Menu>();
	ArrayList<Setting> mSettings = new ArrayList<Setting>();
	ArrayList<JComponent> mJComponents = new ArrayList<JComponent>();
	String mRealName;
	String mDescription;
	
	public Menu(String realName, String description){
		mRealName = realName;
		mDescription = description;
	}
	
	public ArrayList<Menu> getMenus() {
		return mMenus;
	}
	
	public ArrayList<Setting> getSettings() {
		return mSettings;
	}
	
	public String getRealName(){
		return mRealName;
	}
	
	public String getDescription(){
		return mDescription;
	}
	
	public void addMenu(Menu menu) {
		mMenus.add(menu);
	}
	
	public void addSetting(Setting setting){
		mSettings.add(setting);
	}
	
	public ArrayList<JComponent> getJComponents(){
		return mJComponents;
	}
	
	public void addJComponent(JComponent component) {
		mJComponents.add(component);
	}
	
	public void setActionListner(ActionListener actionListener) {
		for (int i = 0; i < mJComponents.size(); i++){
			if (mJComponents.get(i).getClass() == JButton.class) {
				JButton button = (JButton) mJComponents.get(i);
				button.addActionListener(actionListener);
			}
		}
	}
	
	public int getMenuHeight() {
		int height = 10 + 10;
		for (JComponent component : mJComponents) {
			height += (component.getHeight() +10);
		}
		return height;
	}
	
	public void moveMenu(int value) {
		for (int i = 0; i < mJComponents.size(); i++){
			Rectangle oldBounds = mJComponents.get(i).getBounds();
			mJComponents.get(i).setBounds(new Rectangle(oldBounds.x, oldBounds.y + value, oldBounds.width, oldBounds.height));
		}
	}
}
